package com.zt.common.utils;

import com.zt.common.common.ApiException;
import com.zt.common.common.CodeMsg;
import org.apache.shiro.authc.AuthenticationException;

import javax.servlet.http.HttpServletRequest;

/**
 * description:
 * author:zt
 * date:2022-01-09
 */
public class UserUtil {

    public static boolean checkUserStatus(HttpServletRequest request){
        String token = request.getHeader("authorization");
        if (token == null) throw new AuthenticationException("token 不存在");

        if (!JwtUtil.verify(token)) {
            throw new AuthenticationException("access token 过期");
        }
        String id = JwtUtil.decodedGetID(token);
        RedisUtil redisUtil = ApplicationContextUtil.get(RedisUtil.class);
        if (!redisUtil.hasKey(id)) {
            throw new ApiException(CodeMsg.TOKEN_EXPIRE);
        }
        return true;
    }
}
